<template>
  <el-form label-width="120px" ref="formRef" :model="form" :rules="rules">
    <el-row>
#foreach ($sysColumnVo in ${subSysColumnVoList})
  #if($sysColumnVo.isInsert || $sysColumnVo.isEdit && !$sysColumnVo.isPrimaryKey)
    #set($field=$sysColumnVo.javaField)
    #set($parentheseIndex=$sysColumnVo.comment.indexOf("（"))
    #if($parentheseIndex != -1)
      #set($comment=$sysColumnVo.comment.substring(0, $parentheseIndex))
    #else
      #set($comment=$sysColumnVo.comment)
    #end
      <el-col :span="${sysColumnVo.layoutType}">
        <el-form-item label="${comment}" prop="${field}">
    #if($sysColumnVo.dictCode)
      #if($sysColumnVo.htmlType == "select")
          <el-select v-model="form.${field}" placeholder="请选择${comment}">
            <el-option v-for="dict in $sysColumnVo.dictCode" :key="dict.value" :label="dict.label" #if($sysColumnVo.javaType == "Integer" || $sysColumnVo.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end></el-option>
          </el-select>
      #elseif($sysColumnVo.htmlType == "checkbox")
          <el-checkbox-group v-model="form.${field}">
            <el-checkbox v-for="dict in $sysColumnVo.dictCode" :key="dict.value" :label="dict.value">
              {{ dict.label }}
            </el-checkbox>
          </el-checkbox-group>
      #elseif($sysColumnVo.htmlType == "radio")
          <el-radio-group v-model="form.${field}">
            <el-radio v-for="dict in $sysColumnVo.dictCode" :key="dict.value" #if($sysColumnVo.javaType == "Integer" || $sysColumnVo.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>
              {{ dict.label }}
            </el-radio>
          </el-radio-group>
      #end
    #else
      #if($sysColumnVo.htmlType == "input")
          <el-input clearable placeholder="请输入${comment}" v-model="form.${field}"></el-input>
      #elseif($sysColumnVo.htmlType == "imageUpload")
          <jcx-image-upload :file-type="['png', 'jpg']" v-model="form.${field}" v-model:file-path="form.${field}" @update:file-path="form.${field} = $event"></jcx-image-upload>
      #elseif($sysColumnVo.htmlType == "fileUpload")
          <jcx-file-upload v-model="form.${field}"></jcx-file-upload>
      #elseif($sysColumnVo.htmlType == "datetime")
          <el-date-picker clearable v-model="form.${field}" type="datetime" value-format="YYYY-MM-DD HH:mm:ss"  placeholder="请选择${comment}"></el-date-picker>
      #elseif($sysColumnVo.htmlType == "textarea")
          <el-input v-model="form.${field}" type="textarea" placeholder="请输入${comment}" />
      #elseif($sysColumnVo.htmlType == "select")
          <el-select v-model="form.${field}" placeholder="请选择${comment}">
            <el-option label="请选择字典生成" value=""></el-option>
          </el-select>
      #elseif($sysColumnVo.htmlType == "checkbox")
          <el-checkbox-group v-model="form.${field}">
            <el-checkbox>请选择字典生成</el-checkbox>
          </el-checkbox-group>
      #elseif($sysColumnVo.htmlType == "radio")
          <el-radio-group v-model="form.${field}">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
      #end
    #end
        </el-form-item>
      </el-col>
  #end
#end
    </el-row>
  </el-form>
</template>

<script setup lang="js">
import {reactive, ref} from "vue";
#if($subIsUseDict)
import dictUtil from "@/utils/dict";

const {$subDictCodes} = dictUtil.useDictList($subDictCodeList);
#end

const props = defineProps({
  form: {
    type: Object,
    default: {}
  }
})
const formRef = ref(null);
const rules = reactive({
#foreach ($sysColumnVo in ${subSysColumnVoList})
  #if($sysColumnVo.isInsert || $sysColumnVo.isEdit)
    #if($sysColumnVo.isRequired)
      #set($parentheseIndex=$sysColumnVo.comment.indexOf("（"))
      #if($parentheseIndex != -1)
        #set($comment=$sysColumnVo.comment.substring(0, $parentheseIndex))
      #else
        #set($comment=$sysColumnVo.comment)
      #end
  $sysColumnVo.javaField: [
    { required: true, message: "$comment为必填项", trigger: #if($sysColumnVo.htmlType == "select" || $sysColumnVo.htmlType == "radio")"change"#else"blur"#end }
  ]#if($foreach.count != ${subSysColumnVoList.size()}),#end
    #end
  #end
#end
});

const getFormRef = () => { return formRef.value }

defineExpose({getFormRef});
</script>
